﻿
<style>
    .fhui-admin-table-container {
        margin-bottom: 20px;
    }

    .page-layui {
        float: right;
        margin-top: 20px;
    }
</style>

<div class="admin-main" v-cloak id="divAdmin">
    <div class="layui-collapse">
        <div class="layui-colla-item">
            <h2 class="layui-colla-title">查询条件</h2>
            <div class="layui-colla-content layui-show">
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-mid">手机号</label>
                            <div class="layui-input-inline">
                                <input type="text" v-model="searchModel.mobile" class="layui-input layui-unselect" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-mid">发送内容</label>
                            <div class="layui-input-inline">
                                <input type="text" v-model="searchModel.content" class="layui-input layui-unselect" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-mid">身份标签</label>
                            <div class="layui-input-inline">
                                <input type="text" v-model="searchModel.lable" class="layui-input layui-unselect" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-mid">类目标签</label>
                            <div class="layui-input-inline">
                                <input type="text" v-model="searchModel.cate" class="layui-input layui-unselect" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-mid">备注</label>
                            <div class="layui-input-inline">
                                <input type="text" v-model="searchModel.remake" class="layui-input layui-unselect" />
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-mid">最后发短信时间</label>
                            <div class="layui-input-inline">
                                <Date-picker type="datetime" v-model="searchModel.sendBeginTime" format="yyyy-MM-dd HH:mm" placeholder="开始时间" style="width:200px !important;"></Date-picker>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <Date-picker type="datetime" v-model="searchModel.sendEndTime" format="yyyy-MM-dd HH:mm" placeholder="结束时间" style="width:200px !important;"></Date-picker>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-mid">创建时间</label>
                            <div class="layui-input-inline">
                                <Date-picker type="datetime" v-model="searchModel.createBeginTime" format="yyyy-MM-dd HH:mm" placeholder="开始时间" style="width:200px !important;"></Date-picker>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <Date-picker type="datetime" v-model="searchModel.createEndTime" format="yyyy-MM-dd HH:mm" placeholder="结束时间" style="width:200px !important;"></Date-picker>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <div class="layui-inline">
                                <input type="button" class="layui-btn  layui-btn-small " v-on:click="search(1)" value="搜索" />
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="layui-collapse">
        <div class="layui-colla-item">
            <h2 class="layui-colla-title">查询结果</h2>
            <div class="layui-colla-content layui-show">
                <div class="fhui-admin-table-container">
                    <div is="i-table" height="450" size="small" :data="items" border :columns="tableColumns" v-on:on-selection-change="changeSelection" ref="table">
                    </div>
                    <div class="layui-inline page-layui" style="float:right">
                        <Page :total="totalCount" :current="currPage" :page-size="pageSize" :placement="place" v-on:on-change="changePage" v-on:on-page-size-change="pageClick" show-elevator show-sizer show-total></Page>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>

@section scripts{
    <script src="~/lib/MyDate97/WdatePicker.js"></script>
    <script>
        var pageBase = new PageBase();
        var searchModel = '@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(ViewBag.SearchModel))';
        var mobile = '@Request.QueryString["mobile"]';
        var vue = new vueTableBase({
            el: '#divAdmin',
            data: function () {
                return {
                    sendBeginTime: '',
                    sendEndTime: '',
                    createBeginTime: '',
                    createEndTime:'',
                    searchModel: searchModel,
                    defaultSearch: searchModel,
                    isShowSelect: false,
                    getlistUrl: "/js/test.json",
                    pageSize: searchModel.PageSize,
                    currIndex: 0,
                    tableColumns: pageBase.columns
                };
            },
            methods: {
                searchExt() {
                    var keys = ["sendBeginTime", "sendEndTime", "createBeginTime", "createEndTime"];
                    for (var i = 0; i < keys.length; i++) {
                        var item = keys[i];
                        if (this.searchModel[item]) {
                            this.searchModel[item] = this.searchModel[item].format('yyyy-MM-dd hh:mm');
                        }
                    }
                },
                del(row) {
                    this.layerConfirm('确定删除本条信息吗？', '确定', '取消', () => {
                        vue.getSync('/NewPerson/Message/Delete?id=' + row.id, function (msg) {
                            layer.msg(msg.state ? '成功' : '失败', { time: 500 }, function () { vue.search(vue.searchModel.PageIndex) });
                        })
                    })
                },
                senMessage() {
                    parent.window.Tab.tabAdd({
                        href: '/NewPerson/Message/Send',
                        icon: '',
                        title: '发送短信'
                    });
                },
                downLoad() {
                    window.location.href = '/NewPerson/Message/ExportMessageTemplate';
                }
            },
            created: function () {
                if (mobile != '') {
                    this.$data.searchModel.mobile = mobile;
                }
            }
        });







        function PageBase() {
            this.columns = [
                {
                    title: '手机号',
                    key: 'mobile',
                    fixed: 'left',
                    width: 150,
                    align: 'center'
                },
                {
                    title: '内容',
                    key: 'content',
                    align: 'center'
                },
                {
                    title: '身份标签',
                    key: 'label',
                    align: 'center'
                },
                {
                    title: '类目标签',
                    key: 'cate',
                    align: 'center'
                },
                {
                    title: '经营范围',
                    key: 'operateName',
                    align: 'center'
                },
                {
                    title: '备注',
                    key: 'remake',
                    align: 'center'
                },
                {
                    title: '最后发短信时间',
                    key: 'sendTime',
                    align: 'center',
                    render: (h, par) => {
                        return new Date(par.row.sendTime).format("yyyy-MM-dd hh:mm:ss")
                    }
                },
                {
                    title: '创建时间',
                    key: 'reason',
                    align: 'center',
                    render: (h, par) => {
                        return new Date(par.row.createTime).format("yyyy-MM-dd hh:mm:ss")
                    }
                },
                {
                    title: '操作',
                    key: 'action',
                    fixed: "right",
                    width: 120,
                    align: 'center',
                    render: function (h, params) {
                        return [
                            h('a', {
                                style: {
                                    marginRight: '5px',
                                    cursor: 'pointer',
                                    textDecoration: "underline"
                                },
                                on: {
                                    click: function () {
                                        vue.del(params.row)
                                    }
                                }
                            }, '删除')];
                    }
                },
            ];
        }

        layui.use(['layer', 'form', 'upload', 'laypage', 'element', 'laydate'], function () {
            var element = layui.element;
            var form = layui.form
                , laypage = layui.laypage, layer = layui.layer, upload = layui.upload;
            var index = -1;
            var laydate = layui.laydate;
            laydate.render({
                elem: '#sendTime',
                type: 'datetime',
                done: function (value, date, endDate) {
                    vue.$data.sendTime = value;
                }
            });
            upload.render({ //允许上传的文件后缀
                elem: '#test1'
                , url: '/NewPerson/Message/BatchImport'
                , accept: 'file' //普通文件
                , exts: 'xlsx|xls' //只允许上传Excel
                , before: function (input) {
                    //返回的参数item，即为当前的input DOM对象
                    index = layer.load(0, {
                        shade: [0.1, '#fff'] //0.1透明度的白色背景

                    });
                }
                , done: function (res) {
                    layer.close(index);
                    if (res.state == false) {
                        layer.alert(res.msg);
                        return;
                    }
                    vue.$data.fileMsg = res.fileName;
                    vue.$data.fullName = res.fullName;
                    vue.$data.hasFile = true;
                    vue.search();
                }
            });


            laydate.render({
                elem: '#sendBeginTime',
                done: function (value, date, endDate) {
                    vue.$data.sendBeginTime = value;
                }
            });
            laydate.render({
                elem: '#sendEndTime',
                done: function (value, date, endDate) {
                    vue.$data.sendEndTime = value;
                }
            });
            laydate.render({
                elem: '#createBeginTime',
                done: function (value, date, endDate) {
                    vue.$data.createBeginTime = value;
                }
            });
            laydate.render({
                elem: '#createEndTime',
                done: function (value, date, endDate) {
                    vue.$data.createEndTime = value;
                }
            });
        });


    </script>
}


